﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using LeapLibrary;
using Leap;

namespace TronLeapRacing
{
    class PauseMenue
    {
        //Timerzeit
        const float TIMER = 2;

        //Contentmanager
        ContentManager Content;

        //Texturen (Buttons, Cursor, Background)
        Texture2D background;
        Texture2D reStartButton;
        Texture2D backButton;
        Texture2D cursor;

        SpriteFont font;

        //Timer für Fuellanimation
        float timerStart = TIMER;
        float timerBack = TIMER;

        //Leap Koordinaten
        Vector2 handPosition;

        //Hintergrundbild position
        Vector2 bgPosition = new Vector2(0, 0);

        //Game Infos
        Game1 g1ref;

        //Konstruktor
        public PauseMenue(Game1 g1ref)
        {
            this.g1ref = g1ref;
        }

        //Texturen werden aus der Conetentpipeline geladen
        public void LoadContent(ContentManager Content)
        {
            this.Content = Content;
            background = Content.Load<Texture2D>("Background/pauseBackground");
            reStartButton = Content.Load<Texture2D>("Button/TronNeuStart");
            backButton = Content.Load<Texture2D>("Button/TronZurueck");
            cursor = Content.Load<Texture2D>("Texturen/cursor");
            font = Content.Load<SpriteFont>("Font/tronfont");
        }

        //Position der Hand wird abgefragt und Fullanimation wird geladen
        public void Update(Vector2 handPosition, GameTime gameTime)
        {
            this.handPosition = handPosition;

            // überprüfe ob cursor über Textur ist
            if (handPosition.X > -200 && handPosition.X < 165 && handPosition.Y > 200 && handPosition.Y < 280)
            {
                //Timer zaehlt runter
                timerStart -= (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (timerStart < 2.0)
                    reStartButton = Content.Load<Texture2D>("Hover/TronNeuStartHover1");

                if (timerStart < 1.8)
                    reStartButton = Content.Load<Texture2D>("Hover/TronNeuStartHover2");

                if (timerStart < 1.6)
                    reStartButton = Content.Load<Texture2D>("Hover/TronNeuStartHover3");

                if (timerStart < 1.4)
                    reStartButton = Content.Load<Texture2D>("Hover/TronNeuStartHover4");

                if (timerStart < 1.2)
                    reStartButton = Content.Load<Texture2D>("Hover/TronNeuStartHover5");

                if (timerStart < 1)
                    reStartButton = Content.Load<Texture2D>("Hover/TronNeuStartHover6");

                if (timerStart < 0.8)
                    reStartButton = Content.Load<Texture2D>("Hover/TronNeuStartHover7");

                if (timerStart < 0.6)
                    reStartButton = Content.Load<Texture2D>("Hover/TronNeuStartHover8");

                if (timerStart < 0.4)
                    reStartButton = Content.Load<Texture2D>("Hover/TronNeuStartHover9");

                if (timerStart < 0.2)
                    reStartButton = Content.Load<Texture2D>("Hover/TronNeuStartHover10");

                if (timerStart < 0)
                {
                    //Timer wird resetet
                    timerStart = TIMER;
                    g1ref.resetGame();
                    //Gamestate wird auf play gesetzt
                    g1ref.setGamestate("intro");
                }
            }
            else
            {
                timerStart = TIMER;
                reStartButton = Content.Load<Texture2D>("Button/TronNeuStart");
            }

            if (handPosition.X > -150 && handPosition.X < 150 && handPosition.Y > 100 && handPosition.Y < 180)
            {
                //Zeit zaehlt runter
                timerBack -= (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (timerBack < 2)
                    backButton = Content.Load<Texture2D>("Hover/TronZurueckHover1");

                if (timerBack < 1.8)
                    backButton = Content.Load<Texture2D>("Hover/TronZurueckHover2");

                if (timerBack < 1.6)
                    backButton = Content.Load<Texture2D>("Hover/TronZurueckHover3");

                if (timerBack < 1.4)
                    backButton = Content.Load<Texture2D>("Hover/TronZurueckHover4");

                if (timerBack < 1.2)
                    backButton = Content.Load<Texture2D>("Hover/TronZurueckHover5");

                if (timerBack < 1)
                    backButton = Content.Load<Texture2D>("Hover/TronZurueckHover6");

                if (timerBack < 0.8)
                    backButton = Content.Load<Texture2D>("Hover/TronZurueckHover7");

                if (timerBack < 0.6)
                    backButton = Content.Load<Texture2D>("Hover/TronZurueckHover8");

                if (timerBack < 0.4)
                    backButton = Content.Load<Texture2D>("Hover/TronZurueckHover9");

                if (timerBack < 0.2)
                    backButton = Content.Load<Texture2D>("Hover/TronZurueckHover10");

                if (timerBack < 0)
                {
                    //Spiel wird beendet
                    g1ref.setGamestate("play");
                }
            }
            else
            {
                //Timer wird zurueckgesetzt
                timerBack = TIMER;
                backButton = Content.Load<Texture2D>("Button/TronZurueck");
            }

        }

        public void Draw(SpriteBatch spriteBatch, float time, float colisions)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(background, bgPosition, Color.White);
            spriteBatch.Draw(reStartButton, new Vector2(320, 270), Color.White);
            spriteBatch.Draw(backButton, new Vector2(350, 370), Color.White);
            spriteBatch.DrawString(font, "Deine Zeit : " + time.ToString("N2"), new Vector2(180, 180), Color.Aquamarine);
            spriteBatch.DrawString(font, "Deine Kollisionen : " + colisions.ToString("N0"), new Vector2(550, 180), Color.Aquamarine);
            //Zeichnet Cursor an den Leap-Koordinaten
            spriteBatch.Draw(cursor, new Vector2(handPosition.X + 470, -1 * (handPosition.Y - 500)), Color.White);
            spriteBatch.End();
        }
    }
}
